﻿using AutoMapper;
using MediatR;
using SmartProduction.Domain.采购委外订单;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.SCWorkCommand;

namespace SmartProduction.Read.API.Application.CommandHandlers.SCWorkCommandHandler
{
    public class SCLXQueryCommandHandler : IRequestHandler<SCLXQueryCommand, APIPaing<List<ProcessRoute>>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<ProcessRoute> lRepo;

        public SCLXQueryCommandHandler(IMapper mapper, IBaseRepository<ProcessRoute> lRepo)
        {
            this.mapper = mapper;
            this.lRepo = lRepo;
        }

        public async Task<APIPaing<List<ProcessRoute>>> Handle(SCLXQueryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIPaing<List<ProcessRoute>> result = new APIPaing<List<ProcessRoute>>();
                var list = await lRepo.GetAll();
                result.data = list.ToList();
                result.Code = APIEnums.查询成功;
                result.Msg = APIEnums.查询成功.ToString();
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
